import java.util.Arrays;
import java.util.Scanner;

public class LK44_2 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();

        int[][] ints = new int[n][m];
        int sum = 0;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                ints[i][j] = scanner.nextInt();
                sum += ints[i][j];
            }
        }

//        for (int[] anInt : ints) {
//            System.out.println(Arrays.toString(anInt));
//        }
//        System.out.println(sum);

        int[] heng = new int[n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                heng[i] += ints[i][j];
            }
        }
//        System.out.println(Arrays.toString(heng));

        int[] shu = new int[m];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                shu[i] += ints[j][i];
            }
        }
//        System.out.println(Arrays.toString(shu));

        int result = Integer.MAX_VALUE;
        int hengSum = 0;
        for (int i : heng) {
            hengSum += i;
            result = Math.min(result, Math.abs(sum - 2 * hengSum));
        }

        int shuSum = 0;
        for (int i : shu) {
            shuSum += i;
            result = Math.min(result, Math.abs(sum - 2 * shuSum));
        }
        System.out.println(result);

        scanner.close();
    }
}
